<template>
<Row class="layout-content-body">
    <dtable :columnsList="columns" v-model="dataAll" :totals="total" check read  @approveClick="approveClick"  @get="get" @refresh="getall()" :loading="loading"></dtable>
    <Modal v-model="flag" title="确认收件" @on-ok="jdOk">
        <Form ref="editForm" :model="additionForm" :label-width="80" :rules="ruleValidate">
            <Row :gutter="16">
                <Col span="12">
                <Form-item label="案件名称" prop="Title">
                    <Input v-model="additionForm.Title" disabled placeholder="请输入案件名称"></Input>
                </Form-item>
                </Col>
                <Col span="12">
                <Form-item label="案件编号" prop="No">
                    <Input v-model="additionForm.No" disabled placeholder="请输入案件编号"></Input>
                </Form-item>
                </Col>
            </Row>
            <FormItem label="检验类型">
                <Select v-model="additionForm.JdType"  @on-change="jyTypeChange" disabled>
                  <Option v-for="item in jyType" :value="item.value" :key="item.value">{{ item.name }}</Option>
                </Select>
            </FormItem>
            <FormItem label="分类">
                <Select v-model="additionForm.Category"  disabled>
                  <Option v-for="item in jyCategory" :value="item.value" :key="item.value">{{ item.name }}</Option>
                </Select>
            </FormItem>
            <Row :gutter="16">
                <Col span="12">
                <Form-item label="手机号码" prop="Phone">
                    <Input v-model="additionForm.Phone" placeholder="请输入手机号码"></Input>
                </Form-item>
                </Col>
                <Col span="12">
                <FormItem label="是否初检">
                    <RadioGroup v-model="additionForm.First">
                        <Radio v-for="item in chujianArray" :label="item.value" :key="item.value">{{item.name}}</Radio>
                    </RadioGroup>
                </FormItem>
                </Col>
            </Row>
            <Row :gutter="16">
                <Col span="12">
                <FormItem label="预约日期">
                    <DatePicker type="date" :options="dateoptions" :start-date="new Date()" v-model="additionForm.Date"></DatePicker>
                </FormItem>
                </Col>
                <Col span="12">
                <FormItem label="预约时间">
                    <Select v-model="additionForm.Time">
                        <Option v-for="(item,idx) in timeList"  :value="item" :key="idx">{{ item }}</Option>
                      </Select>
                </FormItem>
                </Col>
            </Row>
            <Form-item label="物证信息" prop="Info">
                <Input v-model="additionForm.Info" placeholder="请输入物证信息"></Input>
            </Form-item>
        </Form>
    </Modal>
</Row>
</template>

<script>
import { timeFormat, currency } from "@/common/filter";
import dtable from "@/components/table/etable.vue"; //采用biztable
import moment from "moment";
export default {
  data() {
    return {
      loading: false, //数据刷新遮罩层
      columns: [
        //多选框
        {
          title: "案件名称",
          key: "case_name"
        },
        {
          title: "案件编号",
          key: "no"
        },
        {
          title: "单位",
          key: "dept_name"
        },
        {
          title: "预约人",
          key: "creater"
        },
        {
          title: "检验完成时间",
          key: "ctime",
          render: (h, params) => {
            return h(
              "span",
              {},
              moment(params.row.ctime).format("YYYY-MM-DD HH:mm")
            );
          }
        },
        {
          title: "物证信息",
          key: "content"
        },
        {
          title: "状态",
          key: "name"
        },
        {
          title: "操作",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                    disabled: params.row.lock != 0 ? true : false
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.formItem.Id = params.row.id;
                      this.formItem.User = params.row.creater;
                      this.formItem.Phone = "";
                      // this.next();
                      this.$Modal.confirm({
                        title: "确认信息",
                        content: "<p>确认当前检验已完成吗？</p>",
                        onOk: () => {
                          this.ansyOk();
                        }
                      });
                    }
                  }
                },
                "鉴定完成"
              )
            ]);
          }
        }
      ], //表格样式
      dataAll: [], //表格数据来源
      templist: [],
      dataShow: true, //是否显示表格数据查看表单
      showTemp: false,
      total: 0,
      orderData: {
        edit: true,
        temp: ""
      },
      jyType: [
        {
          name: "痕迹",
          value: 0,
          children: [
            {
              name: "手印",
              value: 0
            },
            {
              name: "足迹",
              value: 1
            },
            {
              name: "工具",
              value: 2
            },
            {
              name: "枪弹",
              value: 3
            },
            {
              name: "特殊",
              value: 4
            },
            {
              name: "爆炸",
              value: 5
            },
            {
              name: "其它",
              value: 6
            }
          ]
        },
        {
          name: "法医",
          value: 1,
          children: [
            {
              name: "尸体",
              value: 0
            },
            {
              name: "活体",
              value: 1
            },
            {
              name: "其它",
              value: 2
            }
          ]
        },
        {
          name: "DNA",
          value: 2,
          children: [
            {
              name: "案件检验",
              value: 0
            },
            {
              name: "违法犯罪人员血样",
              value: 1
            },
            {
              name: "其它",
              value: 2
            }
          ]
        },
        {
          name: "理化",
          value: 3,
          children: [
            {
              name: "毒品",
              value: 0
            },
            {
              name: "毒物",
              value: 1
            },
            {
              name: "微量物证",
              value: 2
            },
            {
              name: "酒精含量",
              value: 3
            },
            {
              name: "其它",
              value: 4
            }
          ]
        },
        {
          name: "文检",
          value: 4,
          children: [
            {
              name: "笔记",
              value: 0
            },
            {
              name: "印章",
              value: 1
            },
            {
              name: "其他",
              value: 2
            }
          ]
        },
        {
          name: "电子物证",
          value: 5,
          children: [
            {
              name: "手机",
              value: 0
            },
            {
              name: "电脑",
              value: 1
            },
            {
              name: "存储设备",
              value: 2
            },
            {
              name: "其它",
              value: 3
            }
          ]
        }
      ],
      jyCategory: [],
      flag: false,
      formItem: {
        Id: "",
        User: "",
        Phone: "",
        Remark: ""
      },
      timeList: [
        "09:00",
        "09:15",
        "09:30",
        "09:45",
        "10:00",
        "10:15",
        "10:30",
        "10:45",
        "11:00",
        "11:15",
        "11:30",
        "13:00",
        "13:15",
        "13:30",
        "13:45",
        "14:00",
        "14:15",
        "14:30",
        "14:45",
        "15:00",
        "15:15",
        "15:30",
        "15:45",
        "16:00",
        "16:15",
        "16:30"
      ],
      dateoptions: {
        disabledDate(date) {
          return date && date.valueOf() < Date.now() - 86400000;
        }
      },
      chujianArray: [
        {
          name: "是",
          value: 1
        },
        {
          name: "否",
          value: 0
        }
      ],
      ruleValidate: {
        JyType: [
          { required: true, message: "请选择鉴定类别", trigger: "change" }
        ],
        Category: [
          { required: true, message: "请选择类型", trigger: "change" }
        ],
        Title: [
          {
            required: true,
            message: "请填写案件名称",
            trigger: "blur"
          }
        ],
        No: [
          {
            required: true,
            message: "请填写案件编号",
            trigger: "blur"
          }
        ],
        Phone: [
          {
            required: true,
            message: "请填写手机号码",
            trigger: "blur"
          }
        ],
        Info: [
          {
            required: true,
            message: "请填写物证信息",
            trigger: "blur"
          }
        ]
      }, //数据编辑表单验证规则
      additionForm: {
        JdType: 0,
        Category: 0,
        First: 1,
        Phone: "",
        Date: new Date(),
        Time: "09:00",
        Info: "",
        Title: "",
        No: "",
        IsAdditional: true,
        CaseId: ""
      },
    };
  },
  components: {
    dtable
  },
  computed: {
    userInfo() {
      return this.$store.state.app.userInfo;
    }
  },
  watch: {},
  methods: {
    // addition(row) {
    //   console.log("addition", row);
    //   this.additionForm.Title = row["case_name"]
    //   this.additionForm.No = row["no"]
    //   this.additionForm.JdType = parseInt(row["jy_type"])
    //   this.jyTypeChange(this.additionForm.JdType)
    //   this.additionForm.Category = parseInt(row["category"]) 
    //   this.additionForm.CaseId = row["busy_id"]
    //   this.flag = true
    // },
    jdQueRen() {
      let times = this.additionForm.Time.split(":");
      this.additionForm.Date.setHours(times[0]);
      this.additionForm.Date.setMinutes(times[1]);
      if (moment()> moment(this.additionForm.Date)) {
        return true
      }
      return false
    },
    jdOk() {
      this.$refs["editForm"].validate(valid => {
        if (valid) {
          if (this.jdQueRen()) {
            this.$Message.error("无效的时间，请重新选择！")
            return
          }
          this.$api.PostCase(this.additionForm).then(res => {
            if (res.code == 0) {
              this.getall();
              this.$Message.success("保存成功!");
              this.$refs["editForm"].resetFields();
            }
          });
        } else {
          this.$Message.error("请补充信息!");
        }
      });
    },
    ansyOk() {
      console.log(this.formItem);
      this.$api.UpdateTodoStatus(this.formItem).then(res => {
        if (res.code == 0) {
          console.log("success");
          this.getall();
        }
      });
    },
    next() {
      this.flag = true;
    },
    getall() {
      this.loading = true;
      let data = {
        busyName: "sf_case"
      };
      this.$api.GetJianDingZhong(data).then(res => {
        console.debug(res.Data);
        if (!res.error) {
          this.dataAll = res.Data;
          if (this.dataAll) {
            this.total = this.dataAll.length;
          }
        } else {
          this.$Message.error(res.message);
        }
      });
      this.loading = false;
    },

    asyncOK() {
      this.$router.push({
        name: "技术人员审批",
        params: {
          orderData: this.orderData
        }
      });
    },
    approveClick(data) {
      this.orderData.order = data;
      this.orderData.edit = true;
      this.$router.push({
        name: "司法检验审核",
        params: {
          orderData: this.orderData
        }
      });
    },
    get(data) {
      console.log(data)
      this.orderData.order = data;
      this.orderData.edit = false;
      this.$router.push({
        name: "司法检验审核",
        params: {
          orderData: this.orderData
        }
      });
    },
    jyTypeChange(idx) {
      console.log(idx);
      for (let i = 0; i < this.jyType.length; i++) {
        if (this.jyType[i].value == idx) {
          this.jyCategory = this.jyType[i].children;
        }
      }
    },
  },
  mounted() {
    this.additionForm.Phone = this.userInfo.Phone;
    // this.getall();
  }
};
</script>
